package com.yixun.qfbao.response.premises;

import com.yixun.qfbao.xf.model.dto.CityGroupDto;
import com.yixun.qfbao.xf.model.dto.PremisesCityDto;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author jhsong
 * @create 2020-8-3 10:43:07
 **/
@Data
public class GetPremisesCityGroupByPinyinResDto implements Serializable {
    private static final long serialVersionUID = -5847692178705321054L;

	private List<CityGroupDto> list;
	
	/**
	 * 添加楼盘城市信息,并按照字母进行分组，放入集合
	 */
	public void addPremisesCityDto(PremisesCityDto premisesCityDto) {
		if(list == null) {
			list = new ArrayList<>();
		}
		boolean addCityGroupFlag = false;
		String premisesCityFirEn = premisesCityDto.getPinyin();
		for (CityGroupDto cityGroupDto : list) {
			if(premisesCityFirEn.equals(cityGroupDto.getCityFirEn())) {
				cityGroupDto.addPremisesCityDto(premisesCityDto);
				addCityGroupFlag = true;
				break;
			}
		}
		if(!addCityGroupFlag) {
			CityGroupDto cityGroupDto = new CityGroupDto(premisesCityFirEn);
			cityGroupDto.addPremisesCityDto(premisesCityDto);
			list.add(cityGroupDto);
		}
	}
}
